package com.quirka.logica;


import java.awt.color.ColorSpace;
import java.awt.image.BufferedImage;
import java.awt.image.BufferedImageOp;
import java.awt.image.ColorConvertOp;

import java.io.File;
import java.io.FileInputStream;

import com.sun.image.codec.jpeg.JPEGCodec;
import com.sun.image.codec.jpeg.JPEGImageDecoder;



public class ConvertirEscalaDeGrises {
    
    public static BufferedImage convertir(File pathImagenColor) {
     
     
    
     
       try { 
           JPEGImageDecoder decoder=JPEGCodec.createJPEGDecoder(new FileInputStream(pathImagenColor));        
           BufferedImage sourceImg=decoder.decodeAsBufferedImage();
           BufferedImageOp op =new ColorConvertOp(
           ColorSpace.getInstance(ColorSpace.CS_GRAY),null);
           return  op.filter(sourceImg,null);


        } 
       catch (Exception e) {  
           e.printStackTrace(); 
       }
    return null;  
      
    }
 }